package com.eclipse.e0114_java8.课堂案列;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test4_分组 {
	static List<String> list = Arrays.asList("1", "22", "333", "333", "3334");

	public static void main(String[] args) {

		System.out.println("---------------------------------------------");
		Stream<String> stream = list.stream();

		// 所有的元素是否能满足指定的条件
//		System.out.println(stream.allMatch(t -> t.length() > 2));

//		String str = list.stream().reduce("初始值,当stream为空,返回这个初始值", (a, b) -> a + b);
//		System.out.println(str);

		// 取最大值
//		stream = list.stream();
//		System.out.println(stream.collect(Collectors.maxBy((a, b) -> a.length() - b.length())));
//
//		// 分组
		stream = list.stream();

		Map<Object, List<String>> groups = stream.collect(Collectors.groupingBy(t -> t.length()));
//
		groups.forEach((k, v) -> {
			// System.out.println(k+"："+v.size());
			System.out.println(k);
			v.forEach(t -> System.out.println("   " + t));
		});

	}

}
